package br.com.last.fm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;

import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;

public class LastFM {
	public static void main(String[] args) {
		DefaultHttpClient client = new DefaultHttpClient();
		HttpGet request;
		try {
			// String url =
			// "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=0cd50f894acf66179bd69d68560d9d91&artist=Lara%20Fabian&album=Pure&format=json";

			String url = "http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=luizromagnoli&api_key=0cd50f894acf66179bd69d68560d9d91";

			request = new HttpGet(url);

			// Proxy
			HttpHost proxy = new HttpHost("localhost", 3128, "http");
			client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
					proxy);

			HttpResponse response = client.execute(request);

			String resultado = "";

			// Get the response
			BufferedReader rd = new BufferedReader(new InputStreamReader(
					response.getEntity().getContent()));

			String line = "";
			while ((line = rd.readLine()) != null) {
				resultado += line;
			}

			System.out.println(resultado);

		} catch (URISyntaxException e) {
			e.printStackTrace();
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
